package com.waste.game.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.waste.game.dao.*;
import com.waste.game.entity.entitiytv.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class VideoBackListController {
    @Autowired
    VideoAllDao videoAllDao;
    @Autowired
    VideoHomeLbtDao videoHomeLbtDao;
    @Autowired
    VideoHomeTopTvDao videoHomeTopTvDao;
    @Autowired
    VideoBugJYDao videoBugJYDao;
    @Autowired
    VideoHomeUpTimeListDao videoHomeUpTimeListDao;
    @Autowired
    VideoPlayerDao videoPlayerDao;

    @GetMapping("/api/videoList/{pageNum}/{pageSize}")
    public PageInfo<VideoAllBean> getSearchVideo(@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize) {
        Page<Object> objects = PageHelper.startPage(pageNum,pageSize);
        List<VideoAllBean> list = videoAllDao.getVideoList();
        return new PageInfo<>(list);
    }
    @GetMapping("/api/videoLbt")
    public List<VideoLbtBean> getVideoLbt() {
        return videoHomeLbtDao.getLbt();
    }
    @RequestMapping("/api/videoTv")
    public List<VideoTopBean> getTvList(){
        return videoHomeTopTvDao.getVideoTopList();
    }
    //获取bug
    @GetMapping("/api/getBUG")
    public List<VideoBugJYBean> getVideoBUG() {
            return videoBugJYDao.selectBug();
    }
    //获取Jy
    @GetMapping("/api/getJY")
    public List<VideoBugJYBean> getVideoJY() {
        return videoBugJYDao.selectJY();
    }
    //消除已知bug
    @GetMapping("/api/deleteBug/{id}")
    public String deleteBug(@PathVariable(value = "id") Integer id) {
        int a = videoBugJYDao.deleteBug(id);
        if (a == 1){
            return "清除成功";
        }else {
            return "服务器娘错误！清除失败！";
        }
    }
    @GetMapping("/api/deleteJY/{id}")
    public String deleteJyOne(@PathVariable(value = "id") Integer id) {
        int a = videoBugJYDao.deleteJy(id);
        if (a == 1){
            return "清除成功";
        }else {
            return "服务器娘错误！清除失败！";
        }
    }
    //获取不能播放信息
    @GetMapping("/api/getNoPlayer")
    public List<VideoBugJYBean> getVideoNoPlayer() {
        return videoBugJYDao.selectNoPlayer();
    }
    //清除不能播放信息
    @GetMapping("/api/deleteNoPlayer/{id}")
    public String getVideoNoPlayer(@PathVariable(value = "id") Integer id) {
        int a = videoBugJYDao.deleteNoPlayer(id);
        if (a == 1){
            return "清除成功";
        }else {
            return "服务器娘错误！清除失败！";
        }
    }
    //查询更新信息
    @GetMapping("/api/getUp/{pageNum}/{pageSize}")
    public PageInfo<VideoUpTimeBean> getVideoUpTimeList(@PathVariable(value = "pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize) {
        Page<Object> objects = PageHelper.startPage(pageNum,pageSize);
        List<VideoUpTimeBean> list = videoHomeUpTimeListDao.getUpList();
        return new PageInfo<>(list);
    }
    //查询某一条视频
    @GetMapping("/api/videoOne/{id}")
    public VideoAllBean getVideoOne(@PathVariable("id") Integer id) {
        return videoAllDao.getVideoOne(id);
    }
    //修改某一条视频
    @PostMapping("/api/videoOneSet")
    public String getVideoOneSet(@RequestBody VideoAllBean videoallBean) {
        int a = videoAllDao.upDateOne(videoallBean);

        if (a == 1){
            return "修改成功";
        }else {
            return "服务器娘错误！修改失败！";
        }
    }
    //添加某一条视频
    @PostMapping("/api/videoOneInt")
    public String getVideoOneInt(@RequestBody VideoAllBean videoallBean) {
        int a = videoAllDao.insertOne(videoallBean);

        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
    //修改某一条轮播图
    @PostMapping("/api/videoLbtSet")
    public String getVideoLbtOne(@RequestBody VideoLbtBean videoLbtBean) {
        int a = videoHomeLbtDao.upDateLbtOne(videoLbtBean);
        if (a == 1){
            return "修改成功";
        }else {
            return "服务器娘错误！修改失败！";
        }
    }
    //查询某一条轮播图
    @GetMapping("/api/videoLbtOne/{id}")
    public VideoLbtBean getLbtOne(@PathVariable("id") Integer id) {
        return videoHomeLbtDao.getLbtOne(id);
    }
    //查询某一条最近更新
    @GetMapping("/api/videoUpOne/{id}")
    public VideoUpTimeBean getVideoUpOne(@PathVariable("id") Integer id) {
        return videoHomeUpTimeListDao.getUpOne(id);
    }
    //修改某一条最近更新
    @PostMapping("/api/videoUpOneSet")
    public String getUpTimeOneSet(@RequestBody VideoUpTimeBean videoUpTimeBean) {
        int a = videoHomeUpTimeListDao.setUpTime(videoUpTimeBean);
        if (a == 1){
            return "修改成功";
        }else {
            return "服务器娘错误！修改失败！";
        }
    }
    //添加某一条视频
    @PostMapping("/api/UpOneInset")
    public String getUpOneInt(@RequestBody VideoUpTimeBean videoUpTimeBean) {
        int a = videoHomeUpTimeListDao.setUpTimeInset(videoUpTimeBean);

        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
    //查询某一条最多播放
    @GetMapping("/api/videoTvOne/{id}")
    public VideoTopBean getTvOne(@PathVariable("id") Integer id) {
        return videoHomeTopTvDao.getTvOne(id);
    }
    //修改某一条最近更新
    @PostMapping("/api/videoTvOneSet")
    public String getTvOneSet(@RequestBody VideoTopBean videoTopBean) {
        int a = videoHomeTopTvDao.setTvOne(videoTopBean);
        if (a == 1){
            return "修改成功";
        }else {
            return "服务器娘错误！修改失败！";
        }
    }
    @GetMapping("/api/deleteUp/{id}")
    public String deleteUp(@PathVariable(value = "id") Integer id) {
        if (videoBugJYDao.deleteJy(id) == 1){
            return "清除成功";
        }else {
            return "服务器娘错误！清除失败！";
        }
    }
    //添加某一条视频
    @PostMapping("/api/urlListInsert")
        public String getUrlListInt(@RequestBody List<VideoEpicBean> videoEpicBean) {
        int a = videoPlayerDao.insertBatchColumn(videoEpicBean);

        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
    //添加某一条反馈
    @PostMapping("/api/fkInsert")
    public String fkInt(@RequestBody VideoBugJYBean videoBugJYBean) {
        int a = videoBugJYDao.fkInsert(videoBugJYBean);
        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
    @PostMapping("/api/jyInsert")
    public String jyInt(@RequestBody VideoBugJYBean videoBugJYBean) {
        int a = videoBugJYDao.jyInsert(videoBugJYBean);
        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
//    @PostMapping("/api/noInsert")
//    public String noInt(@RequestBody VideoBugJYBean videoBugJYBean) {
//        System.out.println(videoBugJYBean);
//        int a = videoBugJYDao.noInsert(videoBugJYBean);
//        if (a == 1){
//            return "添加成功";
//        }else {
//            return "服务器娘错误！添加失败！";
//        }
//    }
    @PostMapping("/api/noInsert/{vepic}/{vname}")
    public String noInt2(@PathVariable("vepic")String vepic,@PathVariable("vname")String vname) {
        VideoBugJYBean videoBugJYBean = new VideoBugJYBean();
        videoBugJYBean.setVEpicN(vepic);
        videoBugJYBean.setVNameN(vname);
        int a = videoBugJYDao.noInsert(videoBugJYBean);
        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
    @GetMapping("/api/videoUrlQuery/{i}/{i2}")
    public VideoEpicBean getEpicSet(@PathVariable("i")String i,@PathVariable("i2")String i2) {
        return videoPlayerDao.getVideoEpicOne(Integer.valueOf(i),Integer.valueOf(i2));

    }
    //修改视频链接，单个
    @PostMapping("/api/videoUrlSet")
    public String setUrlOne(@RequestBody VideoEpicBean videoEpicBean) {
        int a = videoPlayerDao.upUrlOne(videoEpicBean);

        if (a == 1){
            return "添加成功";
        }else {
            return "服务器娘错误！添加失败！";
        }
    }
}
